<?php

namespace app\dao\office;

use app\dao\BaseDao;
use app\model\office\OfficeDatum;

class OfficeDatumDao extends BaseDao
{

    public function index(array $where)
    {
        return $this ->search() ->with(['OfficeClass' =>function($query){
            $query->withField(['id', 'title']);
        }]) -> withSearch(['class_id'],['class_id' => $where['class_id']]) ->where('website_id',$where['website_id']) ->paginate($where['pageSize']);
    }


    public function create(array $where)
    {
        unset($where['id']);
        return $this -> search() -> create($where);
    }

    public function updateDao(array $where)
    {
        unset($where['website_id']);
        return $this ->search() ->update($where);
    }

    public function deleteDao(array $where)
    {
        return $this->getModel()->whereIn('id', $where['id'])->update(['delete_time' => date('Y-m-d H:i:s', time())]);
    }

    protected function setModel(): string
    {
        return OfficeDatum::class;
    }



    //-----------------------------------------api-------------------------------------------------
    public function getDatum(array $where){
        return $this->getModel()
            ->withoutField(['delete_time','create_time','update_time'])
            ->where('class_id',$where['id'])
            ->select();

    }
}